const express = require('express');

const app = express();

app.use((req, res, next)=>{
    res.setHeader('access-control-allow-origin', '*');
    next();
})
//路由规则   
// 类型: GET
// URL: http://192.168.43.23/fapig/nba/rank
// 参数:     key  值随意写
// 响应结果: JSON
app.get('/fapig/nba/rank', (req, res) => {
    let key = req.query.key;
    if(!key){
        return res.json({
            code: '001',
            msg: '参数 key 缺失'
        })
    }
    //判断
    ///响应结果
    res.json({
        "reason": "查询成功!",
        "result": {
            "title": "美国男子职业篮球联赛",
            "duration": "2020-2021",
            "ranking": [{
                "name": "东部排名",
                "type": "east",
                "list": [{
                    "rank_id": "14",
                    "team": "俄克拉荷马城雷霆",
                    "wins": "22",
                    "losses": "50",
                    "wins_rate": "31%",
                    "avg_score": "105.0",
                    "avg_lose_score": "115.6"
                }]
            }]
        },
        "error_code": 0
    })
});

app.listen(80, () => {
    console.log('服务已经启动...');
})